package com.mapps.jurado.fragments;

import java.util.ArrayList;
import java.util.List;

import com.mapps.jurado.R;
import com.mapps.jurado.adapter.ListaNotasAdapter;

import android.annotation.SuppressLint;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

@SuppressLint("NewApi")
public class ListaNotasFragment extends Fragment {

	private ListView listViewNotas;
	private ListaNotasAdapter adapter;
	private List<String> listaNotas;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		return inflater.inflate(R.layout.layout_fragment_notas, null);
	}
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		listaNotas = new ArrayList<String>();
		for(int i = 1; i <= 10; i++){
			listaNotas.add("" + i);
		}
		
		listViewNotas = (ListView) getView().findViewById(R.id.listViewNotas);
		adapter = new ListaNotasAdapter(getActivity(), listaNotas);
		listViewNotas.setAdapter(adapter);
		listViewNotas.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> av, View v, int position, long id) {
				String nota = listaNotas.get(position);
				NotaFragment fragment = new NotaFragment(nota);
				FragmentManager manager = getFragmentManager();
				FragmentTransaction transaction = manager.beginTransaction();
				transaction.replace(R.id.frameLayoutPrincipal, fragment);
				transaction.commit();
			}
		});
	}
	
}
